home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / effects / qteffects explode.win / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.4 KB  |  300 lines

  1. /*
  2.     File:        main.c
  3.     
  4.     Contains:    Code to generate a QuickTime movie with a QuickTime video effect in it.
  5.     
  6.     Written by:    Scott Kuechle
  7.                 (based heavily on QuickTime SDK QTShowEffect sample code by Tim Monroe)
  8.  
  9.     Copyright:    © 1999 by Apple Computer, Inc. All rights reserved
  10.     
  11.     Change History (most recent first)
  12.     
  13.         <1>        9/25/99        srk        first file
  14.         <2>        10/19/99    srk        changed cross fade effect to explode effect
  15.  
  16.  
  17. */
  18.  
  19.  
  20. #ifndef __FONTS__
  21. #include <Fonts.h>
  22. #endif
  23.  
  24. #ifndef __IMAGECODEC__
  25. #include <ImageCodec.h>
  26. #endif
  27.  
  28. #ifndef __MOVIES__
  29. #include <Movies.h>
  30. #endif
  31.  
  32. #ifndef __MOVIESFORMAT__
  33. #include <MoviesFormat.h>
  34. #endif
  35.  
  36. #ifndef __MEDIAHANDLERS__
  37. #include <MediaHandlers.h>
  38. #endif
  39.  
  40. #ifndef __NUMBERFORMATTING__
  41. #include <NumberFormatting.h>
  42. #endif
  43.  
  44. #ifndef __QUICKTIMECOMPONENTS__
  45. #include <QuickTimeComponents.h>
  46. #endif
  47.  
  48. #ifndef __ENDIAN__
  49. #include <Endian.h>
  50. #endif
  51.  
  52. #ifndef __GESTALT__
  53. #include <Gestalt.h>
  54. #endif
  55.  
  56. #ifndef __FIXMATH__
  57. #include <FixMath.h>
  58. #endif
  59.  
  60. #ifndef __MACWINDOWS__
  61. #include <MacWindows.h>
  62. #endif
  63.  
  64. #ifndef __PRINTING__
  65. #include <Printing.h>
  66. #endif
  67.  
  68. #ifndef __SCRIPT__
  69. #include <Script.h>
  70. #endif
  71.  
  72. #ifndef __SOUND__
  73. #include <Sound.h>
  74. #endif
  75.  
  76. #ifndef _STRING_H
  77. #include <string.h>
  78. #endif
  79.  
  80. #ifndef _STDLIB_H
  81. #include <stdlib.h>
  82. #endif
  83.  
  84. #ifndef __TEXTUTILS__
  85. #include <TextUtils.h>
  86. #endif
  87.  
  88. #ifndef __TRAPS__
  89. #include <Traps.h>
  90. #endif
  91.  
  92. #ifndef __RESOURCES__
  93. #include <Resources.h>
  94. #endif
  95.  
  96. #ifndef __FILETYPESANDCREATORS__
  97. #include <FileTypesAndCreators.h>
  98. #endif
  99.  
  100. #if TARGET_OS_WIN32
  101.         // Windows headers
  102.     #define    STRICT
  103.     #include <windows.h>
  104.         // QTML stuff
  105.     #include "QTML.h"
  106. #endif
  107.  
  108.  
  109. #include "Main.h"
  110. #include "QTEffects.h"
  111.  
  112.  
  113. // miscellaneous constants
  114. #define kMsgDialogRsrcID                129
  115. #define kMsgItemID                        3    
  116.  
  117.  
  118. #if TARGET_OS_WIN32
  119.     short  gAppResID;
  120. #endif
  121.  
  122. #if TARGET_OS_MAC
  123.  
  124.  
  125. ////////////////////
  126. //
  127. // Main (Mac)
  128. //
  129. ////////////////////
  130.  
  131. void main( void )
  132. {
  133.     Movie movie;
  134.  
  135.  
  136.     InitMacToolbox ();
  137.     QuickTimeInit();
  138.         /* Create our effects movie */
  139.     movie = QTEffects_CreateEffectsMovie ();
  140. }
  141.  
  142. #else if TARGET_OS_WIN32
  143.  
  144.  
  145. ////////////////////
  146. //
  147. // Main (Windows)
  148. //
  149. ////////////////////
  150.  
  151. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  152.                     LPSTR lpszCmdLine, int nCmdShow)
  153.  
  154. {
  155.     Movie movie;
  156.  
  157.  
  158.     QuickTimeInit();
  159.  
  160.         /* Create our effects movie */
  161.     movie = QTEffects_CreateEffectsMovie ();
  162.  
  163.     #if TARGET_OS_WIN32
  164.         if (gAppResID != -1)
  165.             CloseResFile(gAppResID);
  166.     #endif
  167.  
  168.     return 0;
  169. }
  170.  
  171. #endif
  172.  
  173.  
  174. #if TARGET_OS_MAC
  175.  
  176. ////////////////////
  177. //
  178. // InitMacToolbox
  179. // Standard Macintosh Toolbox Initialization
  180. //
  181. ////////////////////
  182.  
  183. static void InitMacToolbox (void)
  184. {
  185.     InitGraf (&qd.thePort);
  186.     InitFonts ();
  187.     InitWindows ();
  188.     InitMenus ();
  189.     TEInit ();
  190.     InitDialogs (nil);
  191. }
  192.  
  193. #endif
  194.  
  195. ////////////////////
  196. //
  197. // QuickTimeInit
  198. // Initialize QuickTime here
  199. //
  200. ////////////////////
  201.  
  202. static void QuickTimeInit (void)
  203. {
  204.     OSErr err;
  205.  
  206.     #if TARGET_OS_WIN32
  207.     char   szAppPathName[256];
  208.     FSSpec resFSSpec;
  209.  
  210.     err = InitializeQTML(0L);
  211.     CheckError (err, "InitializeQTML error" );
  212.     
  213.     GetModuleFileName(0, szAppPathName, 256);
  214.     NativePathNameToFSSpec(szAppPathName, &resFSSpec, kFullNativePath);
  215.     gAppResID = FSpOpenResFile(&resFSSpec, fsRdWrPerm);
  216.  
  217.     #endif
  218.  
  219.     err = EnterMovies ();
  220.  
  221.     CheckError (err, "EnterMovies error" );
  222. }
  223.  
  224. ////////////////////
  225. //
  226. // Utils_Macintosh_DisplayMsg
  227. // Displays error messages for Macintosh sample code.
  228. //
  229. ////////////////////
  230.  
  231. #if TARGET_OS_MAC
  232. static void Macintosh_DisplayMsg(char *msg)
  233. {
  234.     DialogPtr theDlog;
  235.     Handle item = NULL;
  236.     Rect box;
  237.  
  238.         theDlog = GetNewDialog(kMsgDialogRsrcID, NULL, (WindowPtr)-1);
  239.         if (theDlog != NULL)
  240.         {
  241.             short itemType;
  242.             
  243.                 GetDialogItem(theDlog, kMsgItemID, &itemType, &item, &box);
  244.                 if (item != NULL)
  245.                 {
  246.                     short itemHit;
  247.                     
  248.                         SetDialogItemText(item, c2pstr(msg));
  249.                         ModalDialog(NULL, &itemHit);
  250.                         DisposeDialog(theDlog);
  251.                         p2cstr((StringPtr)msg);    /* restore C-string */
  252.                 }
  253.         }
  254.  
  255. }
  256. #endif
  257.  
  258. ////////////////////
  259. //
  260. // Utils_Win32_DisplayMsg
  261. // Displays error messages for Win95/NT sample code.
  262. //
  263. ////////////////////
  264.  
  265. #if TARGET_OS_WIN32
  266. static void Win32_DisplayMsg(char *msg)
  267. {
  268.  
  269.     MessageBox(NULL, msg, "", MB_OK);
  270. }
  271. #endif
  272.  
  273.  
  274. ////////////////////
  275. //
  276. // CheckError
  277. // Displays error message if an error occurred
  278. //
  279. ////////////////////
  280.  
  281. void CheckError(OSErr error, char *msg)
  282. {
  283.     if (error == noErr)
  284.     {
  285.         return;
  286.     }
  287.     if (strlen(msg) > 0)
  288.     {
  289.         #if TARGET_OS_MAC
  290.             Macintosh_DisplayMsg(msg);
  291.         #else if TARGET_OS_WIN32
  292.             Win32_DisplayMsg(msg);
  293.         #endif
  294.         
  295.  
  296.         ExitToShell();
  297.  
  298.     }
  299. }
  300.